<template>
  <div class="wrapper">
    <JForm :form-config="dynamicValidateForm" @handleBoxEvent="handleBoxEvent" />
  </div>
</template>

<script>
import JForm from '@/components/JForm'
import { getDictListByType } from '@/api/dictionaries'

export default {
  name: 'ClientUpdate',
  components: { JForm },
  props: {
    emitData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    const userInfo = [
      {
        name: 'dictTypeName',
        label: '类型名称',
        type: 'string',
        required: true,
        placeholder: ''
      },
      {
        name: 'dictTypeCode',
        label: '类型编码',
        type: 'string',
        required: true
      },
      {
        name: 'delEnabled',
        label: '允许删除',
        type: 'switch',
        required: true,
        value: 'N',
        config: {
          activeText: '是',
          inactiveText: '否',
          activeValue: 'Y',
          inactiveValue: 'N'
        }
      },
      {
        name: 'isTree',
        label: '是否树形结构',
        type: 'switch',
        required: false,
        value: '0',
        config: {
          activeText: '是',
          inactiveText: '否',
          activeValue: '1',
          inactiveValue: '0'
        }
      },
      {
        name: 'sortNum',
        label: '排序',
        type: 'string',
        required: false
      },
      {
        name: 'note',
        label: '备注',
        type: 'string',
        required: false
      }
    ]
    return {
      userInfo,
      formName: 'dynamicValidateForm',
      DicYN: [],
      DicYN01: []
    }
  },
  computed: {
    dynamicValidateForm() {
      const data = this.userInfo
      const result = data
      result.forEach(item => {
        const { name } = item
        item.value = this.emitData[name]
      })
      return result
    }
  },
  watch: {},
  created() {
    // 查询字典
    this.getDicYN()
    this.getDicYN01()
  },
  mounted() {},
  methods: {
    getDicYN() {
      getDictListByType({ dictTypeCode: 'YN' }).then(res => {
        const { code, data /* message */ } = res
        if (code === 200) { this.DicYN = data }
        console.log('YN', res)
      })
    },
    getDicYN01() {
      getDictListByType({ dictTypeCode: 'YN01' }).then(res => {
        console.log('YN01', res)
        const { code, data /* message */ } = res
        if (code === 200) { this.DicYN01 = data }
      })
    },
    handleBoxEvent(emitObj) {
      this.$emit('handleBoxEvent', { target: emitObj })
    }
  }
}
</script>
<style lang="scss" scoped>
.wrapper{
   padding: 0px;
   margin: 0px;
}
</style>
